package com.yangff.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yangff.api.client.UserClient;
import com.yangff.entity.admin.entity.Usermanagement;
import com.yangff.entity.user.entity.User;
import com.yangff.entity.user.entity.dto.UserDTO;
import com.yangff.entity.user.entity.vo.UserVo;
import com.yangff.entity.vo.ResultVo;
import com.yangff.mapper.UsermanagementMapper;
import com.yangff.service.IUsermanagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 存储管理员对用户的管理操作记录 服务实现类
 * </p>
 *
 * @author yangff
 * @since 2025-01-15
 */
@Service
@RequiredArgsConstructor
public class UsermanagementServiceImpl extends ServiceImpl<UsermanagementMapper, Usermanagement> implements IUsermanagementService {
    private final UserClient userClient;


    @Override
    public Page<UserVo> selectUser(Pageable pageable) {
        Page<User> userPage = userClient.selectUserPage(pageable);

        Page<UserVo> userVoPage = new Page<>(userPage.getCurrent(), userPage.getSize(), userPage.getTotal());
        userVoPage.setRecords(BeanUtil.copyToList(userPage.getRecords(), UserVo.class));
        return userVoPage;
    }

    @Override
    public UserVo updateUserStatusByAccount(UserDTO userDTO) {
        // 如果为空，则默认为0，锁住，为不正常的修改
        if(userDTO.getStatus() == null) userDTO.setStatus((byte) 0);

        return userClient.updateUserStatusByAccount(userDTO);
    }

    @Override
    public UserVo updateUserByAccount(UserDTO userDTO) {
        return userClient.updateUserByAccount(userDTO);
    }

    @Override
    public ResultVo deleteUserByAccount(String account) {
        return userClient.deleteUserByAccount(account);
    }
}
